<?php
if(isset($_GET['id'])){
    $manu = $Bus->Manufacture->getItemById($_GET['id']);
    if($manu){
        $manu->manufactures_status = $manu->manufactures_status?0:1;      
        $Bus->Manufacture->update($manu,"idmanufactures='{$manu->idmanufactures}'");
    }
}
require_once WEB_ROOT.'/application/library/Pager.php';
$pager = new Pager(array(
    'rowperpage' =>10,
    'total_rows' =>$Bus->Manufacture->countTotalRow(),
    'currentpage'=>(isset($_GET['page']) && intval($_GET['page']) > 0)?$_GET['page']:1,
    'link'       =>url('admin','mans-manager')
));



$Dtos = $Bus->Manufacture->getItemsPager($pager->getRowStart() ,$pager->getRowPerPage());
$index = 1; 
include 'component/header.php';
include 'component/slidebar.php'; 
?>
<script type="text/javascript">
$(function(){
    $(".btStatus").click(function(){
        var img = $(this).children('img');
        var link = $(this).attr('href');
        $.ajax({
            url: link,
            success: function(data){
                if(img.attr('src') == "css/images/icon/success.png"){
                    img.attr('src','css/images/icon/error.png');
                }else{
                    img.attr('src','css/images/icon/success.png');
                }
            }
        });
        return false;
    });
});
</script>
<!-- BEGIN CONTENT -->
<div id="content">
    <div class="box-out">
    	<div class="box-in">
    		<div class="box-head"><h1>Quản lý nhà sản xuất...</h1></div>
    		<div class="box-content">
                <div class="table">
    				<form>
    					<table>
    						<thead>
    							<tr>
    								<td><div>Tên nhà sản xuất</div></td>
                                    <td><div>Logo</div></td>
                                    <td><div>Trạng thái</div></td>
    								<td><div>Actions</div></td>
    							</tr>
    						</thead>
    						<tbody>
                            <?php foreach($Dtos as $key=> $dto) { $class = ($index%2)?"class='even'":"class='odd'"; ?>
    							<tr>
    								<td>
                                        <div <?php echo $class;?>> <a href="/?mod=admin&act=mans-detail&id=<?php echo $dto->idmanufactures;?>"><?php echo $dto->manufactures_name; ?></a></div>
                                    </td>
                                    <td>
                                        <div <?php echo $class;?>><img class="logo-manufacture" src="<?php echo $dto->manufactures_logo;?>" /></div>
                                    </td>
                                    <td>
                                        <div <?php echo $class;?> >
                                            <?php if($dto->manufactures_status){?>
                                            <a title="Click để thay đổi trạng thái" class="btStatus tooltip" href="<?php echo url('admin','mans-manager', array('id'=>$dto->idmanufactures));?>">
                                                <img src="css/images/icon/success.png" />
                                            </a>
                                            <?php }else{?>
                                            <a title="Click để thay đổi trạng thái" class="btStatus tooltip" href="<?php echo url('admin','mans-manager', array('id'=>$dto->idmanufactures));?>" >
                                                <img src="css/images/icon/error.png" />
                                            </a>
                                            <?php } ?>
                                        </div>
                                    </td>
    								<td class="action">
                                        <div <?php echo $class;?>>
                                            <a class="tooltip" href="<?php echo url('admin','mans-edit',array('id'=>$dto->idmanufactures));?>" title="Sửa thông tin nhà sản xuất">Sữa</a> - 
                                            <a class="tooltip" href="<?php echo url('admin','mans-del',array('id'=>$dto->idmanufactures));?>" title="Xóa thông tin nhà sản xuất">Xóa</a>
                                        </div>
                                    </td>
    							</tr>
                            <?php $index++; } ?>
    						</tbody>
    					</table>
    					<div class="actions">
                            <a class="apply" href="<?php echo url('admin','mans-add');?>">Thêm mới</a>
    					</div><!-- end div .actions -->
                        <div class="pagination">
                            <?php  $pager->showPager(); ?>
                        </div>
                        
    				</form>
    			</div>
    		</div><!-- end div .box-content -->
    	</div><!-- end div .box-in -->
</div><!-- end div #content -->
<!-- END CONTENT -->

<?php
include 'component/footer.php'; 
?>
